{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0045a716",
   "metadata": {},
   "source": [
    "# 本周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fb678a6",
   "metadata": {},
   "source": [
    "## 知识概念"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f89d75b3",
   "metadata": {},
   "source": [
    ">1.一切都是I/O：软工到产品的一般化知识                \n",
    ">2.语音识别:speech recognition                \n",
    ">3.语音唤醒                      \n",
    ">4.自动语音识别:Automatic Speech Recognition, 简称 ASR  \n",
    ">\n",
    ">>1.其目标是以电脑自动将人类的语音内容转换为相应的文字。与说话人识别及说话人确认不同，后者尝试识别或确认发出语音的说话人而非其中所包含的词汇内容。 \n",
    ">\n",
    ">1.语音合成:text to speech,简称 TTS                  \n",
    ">> 1.将文字转化为语音的一种技术，类似于人类的嘴巴，通过不同的音色说出想表达的内容。 在语音合成技术中，主要分为 语言分析部分 和 声学系统部分 ，也称为 前端部分 和 后端部分， 语言分析部分主要是根据输入的文字信息进行分析，生成对应的语言学规格书，想好该怎么读；声学系统部分主要是根据语音分析部分提供的语音学规格书，生成对应的音频，实现发声的功能。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "57fb01e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"text\":\"今天天气很糟糕\",\"items\":[{\"uri\":\"\",\"formal\":\"\",\"ne\":\"\",\"item\":\"今天\",\"loc_details\":[],\"basic_words\":[\"今天\"],\"byte_offset\":0,\"byte_length\":4,\"pos\":\"\"},{\"uri\":\"\",\"formal\":\"\",\"ne\":\"\",\"item\":\"天气\",\"loc_details\":[],\"basic_words\":[\"天气\"],\"byte_offset\":4,\"byte_length\":4,\"pos\":\"n\"},{\"uri\":\"\",\"formal\":\"\",\"ne\":\"\",\"item\":\"很糟糕\",\"loc_details\":[],\"basic_words\":[\"很\",\"糟糕\"],\"byte_offset\":8,\"byte_length\":6,\"pos\":\"a\"}],\"log_id\":1650344937110535132}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "API_KEY = \"Hfdxb7Ex5EuQnNMcxBMsfiYX\"\n",
    "SECRET_KEY = \"OQzz0XivOrlGkshpb0AYqEhXnVXaccE6\"\n",
    "\n",
    "def main():\n",
    "        \n",
    "    url = \"https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?charset=UTF-8&access_token=\" + get_access_token()\n",
    "    \n",
    "    payload = json.dumps({\n",
    "        \"text\": \"今天天气很糟糕\"\n",
    "    })\n",
    "    headers = {\n",
    "        'Content-Type': 'application/json',\n",
    "        'Accept': 'application/json'\n",
    "    }\n",
    "    \n",
    "    response = requests.request(\"POST\", url, headers=headers, data=payload)\n",
    "    \n",
    "    print(response.text)\n",
    "    \n",
    "\n",
    "def get_access_token():\n",
    "    \"\"\"\n",
    "    使用 AK，SK 生成鉴权签名（Access Token）\n",
    "    :return: access_token，或是None(如果错误)\n",
    "    \"\"\"\n",
    "    url = \"https://aip.baidubce.com/oauth/2.0/token\"\n",
    "    params = {\"grant_type\": \"client_credentials\", \"client_id\": API_KEY, \"client_secret\": SECRET_KEY}\n",
    "    return str(requests.post(url, params=params).json().get(\"access_token\"))\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8dd506ad",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
